package com.sjy.ylxt.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageInfo;
import com.sjy.ylxt.entity.basic.ResultBody;
import com.sjy.ylxt.entity.domain.YlxtAdmin;
import com.sjy.ylxt.entity.dto.QueryEscortsDTO;
import com.sjy.ylxt.enums.DeleteFlagEnum;
import com.sjy.ylxt.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import com.sjy.ylxt.mapper.YlxtEscortsMapper;
import com.sjy.ylxt.entity.domain.YlxtEscorts;
import com.sjy.ylxt.service.YlxtEscortsService;

import javax.annotation.Resource;
import java.util.List;

/**
* @Author: 史俊颖
* @CreateTime: 2024-12-12
* @Description: ${description}
*/
@Service
@Slf4j
public class YlxtEscortsServiceImpl extends ServiceImpl<YlxtEscortsMapper, YlxtEscorts>  implements YlxtEscortsService{

    @Resource
    private YlxtEscortsMapper ylxtEscortsMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return ylxtEscortsMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(YlxtEscorts record) {
        return ylxtEscortsMapper.insert(record);
    }

    @Override
    public int insertSelective(YlxtEscorts record) {
        return ylxtEscortsMapper.insertSelective(record);
    }

    @Override
    public YlxtEscorts selectByPrimaryKey(Integer id) {
        return ylxtEscortsMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(YlxtEscorts record) {
        return ylxtEscortsMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(YlxtEscorts record) {
        return ylxtEscortsMapper.updateByPrimaryKey(record);
    }

    /**
     * 陪诊员分页查询列表
     * @param dto
     * @return
     */
    @Override
    public ResultBody<?> pageList(QueryEscortsDTO dto) {
        try{
            log.info("==> 陪诊员分页查询列表");
            LambdaQueryWrapper<YlxtEscorts> qw = new LambdaQueryWrapper<>();
            qw.eq(StringUtils.isNotEmpty(dto.getUserName()),YlxtEscorts::getUserName,dto.getUserName());
            qw.eq(StringUtils.isNotEmpty(dto.getPhoneNumber()),YlxtEscorts::getPhoneNumber,dto.getPhoneNumber());
            qw.eq(StringUtils.isNotEmpty(dto.getEmail()),YlxtEscorts::getUserName,dto.getEmail());
            qw.orderByDesc(YlxtEscorts::getCreateTime);
            List<YlxtEscorts> ylxtEscorts = ylxtEscortsMapper.selectList(qw);
            PageInfo<YlxtEscorts> pageInfo = new PageInfo<>(ylxtEscorts);
            return ResultBody.success(pageInfo);
        }catch (Exception e){
            log.error("==> 陪诊员分页查询列表失败,报错信息为{}",e.getMessage());
            return ResultBody.error("查询陪诊员列表失败");
        }
    }

    /**
     * 禁用陪诊员
     * @param id
     * @return
     */
    @Override
    public ResultBody<?> disable(String id) {
        try{
            log.info("==> 开始禁用陪诊员");
            YlxtEscorts ylxtEscorts = ylxtEscortsMapper.selectByPrimaryKey(Integer.valueOf(id));
            ylxtEscorts.setDeleteFlag(DeleteFlagEnum.DELETE_FLAG.getCode());
            ylxtEscortsMapper.updateByPrimaryKey(ylxtEscorts);
            log.info("==> 禁用陪诊员成功");
            return ResultBody.success();
        }catch (Exception e){
            log.error("==> 禁用陪诊员失败,报错信息为{}",e.getMessage());
            return ResultBody.error("禁用陪诊员失败");
        }
    }

    /**
     * 启用陪诊员
     * @param id
     * @return
     */
    @Override
    public ResultBody<?> enable(String id) {
        try{
            log.info("==> 开始启用陪诊员");
            YlxtEscorts ylxtEscorts = ylxtEscortsMapper.selectByPrimaryKey(Integer.valueOf(id));
            ylxtEscorts.setDeleteFlag(DeleteFlagEnum.UN_DELETE_FLAG.getCode());
            ylxtEscortsMapper.updateByPrimaryKey(ylxtEscorts);
            log.info("==> 启用陪诊员成功");
            return ResultBody.success();
        }catch (Exception e){
            log.error("==> 启用陪诊员失败,报错信息为{}",e.getMessage());
            return ResultBody.error("启用陪诊员失败");
        }
    }

    /**
     * @param id
     * @return
     */
    @Override
    public ResultBody<?> detail(String id) {
        return null;
    }

}
